home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Science / µSim 1.0b5 folder / source / Main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-01  |  17.1 KB  |  686 lines  |  [TEXT/MMCC]

  1. /*
  2. Copyright © 1993,1994 by Fabrizio Oddone
  3. ••• ••• ••• ••• ••• ••• ••• ••• ••• •••
  4. This source code is distributed as freeware: you can copy, exchange, modify this
  5. code as you wish. You may include this code in any kind of application: freeware,
  6. shareware, or commercial, provided that full credits are given.
  7. You may not sell or distribute this code for profit.
  8. */
  9.  
  10. //#pragma load "MacDump"
  11.  
  12. #include    "UtilsSys7.h"
  13. #include    "AEHandlers.h"
  14. #include    "CursorBalloon.h"
  15. #include    "ControlStore.h"
  16. #include    "Disasm.h"
  17. #include    "Dump.h"
  18. #include    "DoMenu.h"
  19. #include    "Globals.h"
  20. #include    "InitMenus.h"
  21. #include    "Input.h"
  22. #include    "Main.h"
  23. #include    "Microprogram_Ed.h"
  24. #include    "Preferences.h"
  25. #include    "Simulator.h"
  26. #include    "SimUtils.h"
  27.  
  28. #if defined(FabSystem7orlater)
  29.  
  30. #pragma segment __%Main
  31.  
  32. extern void _DATAINIT(void);
  33.  
  34. static void DomyKeyEvent(EventRecord *);
  35. static void DoDiskEvent(void);
  36. static void MyZoom(WindowPtr whichWindow, short code);
  37. static Boolean CheckTheStack(void);
  38. static void AdjustMenus(void);
  39. static void AEErrorAlert(OSErr reason);
  40.  
  41. void main(void);
  42.  
  43.  
  44. /* DomyKeyEvent: we got a key down, of course */
  45.  
  46. void DomyKeyEvent(EventRecord *evt)
  47. {
  48. enum {
  49. kUndoKey = 0x7A10,
  50. kCutKey = 0x7810,
  51. kCopyKey = 0x6310,
  52. kPasteKey = 0x7610,
  53. kHelpKey = 0x7205,
  54. kFwdDel = 0x757F,
  55. kHomeKey = 0x7301,
  56. kEndKey = 0x7704,
  57. kPgUpKey = 0x740B,
  58. kPgDnKey = 0x790C,
  59. kClearKey = 0x471B,
  60. kEnterKey = 0x4C03
  61. };
  62.  
  63. register WindowPtr    frontW;
  64. register short    txtStart;
  65. register unsigned char    ch;
  66.  
  67. frontW = FrontWindow();
  68. ch = CHARFROMMESSAGE(evt->message);
  69. if (evt->modifiers & cmdKey) {
  70.     AdjustMenus();
  71.     Handle_My_Menu(MenuKey(ch));
  72.     }
  73. else {
  74.     switch ((unsigned short)evt->message) {
  75.         case kUndoKey    :    Handle_My_Menu((kRes_Menu_Edit << 16) + kMItem_Undo);
  76.             break;
  77.         case kCutKey    :    Handle_My_Menu((kRes_Menu_Edit << 16) + kMItem_Cut);
  78.             if (gWPtr_Microprogram_Ed == frontW)
  79.                 Key_Microprogram_Ed(evt, true);
  80.             break;
  81.         case kCopyKey    :    Handle_My_Menu((kRes_Menu_Edit << 16) + kMItem_Copy);
  82.             break;
  83.         case kPasteKey    :    Handle_My_Menu((kRes_Menu_Edit << 16) + kMItem_Paste);
  84.             if (gWPtr_Microprogram_Ed == frontW)
  85.                 Key_Microprogram_Ed(evt, true);
  86.             break;
  87.         case kHelpKey    :    (void)HMSetBalloons(1 - HMGetBalloons());
  88.                             RecalcMouseRegion(frontW, evt->where);
  89.             break;
  90.         case kFwdDel    :
  91.             if (gTheInput) {
  92.                 if ((txtStart = (*gTheInput)->selStart) == (*gTheInput)->selEnd)
  93.                     TESetSelect(txtStart, txtStart + 1, gTheInput);
  94.                 TEDelete(gTheInput);
  95.                 if (gWPtr_Microprogram_Ed == frontW)
  96.                     Key_Microprogram_Ed(evt, true);
  97.                 }
  98.             break;
  99.         case kClearKey    :
  100.             if (gTheInput) {
  101.                 TEDelete(gTheInput);
  102.                 if (gWPtr_Microprogram_Ed == frontW)
  103.                     Key_Microprogram_Ed(evt, true);
  104.                 }
  105.             break;
  106.         case kHomeKey    :
  107.             if (gWPtr_Dump == frontW)
  108.                 DumpHome();
  109.             else if (gWPtr_Disasm == frontW)
  110.                 DisasmHome();
  111.             else if (gWPtr_IO == frontW)
  112.                 IOHome();
  113.             break;
  114.         case kEndKey    :
  115.             if (gWPtr_Dump == frontW)
  116.                 DumpEnd();
  117.             else if (gWPtr_Disasm == frontW)
  118.                 DisasmEnd();
  119.             else if (gWPtr_IO == frontW)
  120.                 IOEnd();
  121.             break;
  122.         case kPgUpKey    :
  123.             if (gWPtr_Dump == frontW)
  124.                 DumpPgUp();
  125.             else if (gWPtr_Disasm == frontW)
  126.                 DisasmPgUp();
  127.             else if (gWPtr_IO == frontW)
  128.                 IOPgUp();
  129.             break;
  130.         case kPgDnKey    :
  131.             if (gWPtr_Dump == frontW)
  132.                 DumpPgDn();
  133.             else if (gWPtr_Disasm == frontW)
  134.                 DisasmPgDn();
  135.             else if (gWPtr_IO == frontW)
  136.                 IOPgDn();
  137.             break;
  138.         case kEnterKey:
  139.             if (gTheInput) {
  140.                 TESelView(gTheInput);
  141.                 if (gWPtr_IO == frontW)
  142.                     AdjustScrollbars(frontW, false);
  143.                 }
  144.             break;
  145.         default:
  146.             if (gWPtr_Microprogram_Ed == frontW)
  147.                 Key_Microprogram_Ed(evt, false);
  148.             else
  149.                 DoKeyDown(frontW, ch, true);
  150.         }
  151.     }
  152. }
  153.  
  154. /* DoDiskEvent: checks for inserted disks */
  155.  
  156. void DoDiskEvent(void)
  157. {
  158. if (HiWrd(gMyEvent.message)) {
  159. //    myEvent.where.h = ((qd.screenBits.bounds.right - qd.screenBits.bounds.left)>>1) - (304 / 2);
  160. //    myEvent.where.v = ((qd.screenBits.bounds.bottom - qd.screenBits.bounds.top) / 3) - (104 / 2);
  161.     InitCursor();
  162.     DILoad();
  163.     (void)DIBadMount(gMyEvent.where, gMyEvent.message);
  164.     DIUnload();
  165.     }
  166. }
  167.  
  168. /* DoZoom: a window was zoomed */
  169.  
  170. void MyZoom(WindowPtr whichWindow, short code)
  171. {
  172. Rect    globalPortRect, theSect, zoomRect;
  173. GDHandle    nthDevice, dominantGDevice;
  174. register RectPtr    rectP;
  175. long    sectArea, greatestArea;
  176. short    bias;
  177.  
  178. /* theEvent is a global EventRecord from the main event loop */
  179. /* savePort is a global GrafPtr for scratch */
  180.  
  181. EraseRect(&whichWindow->portRect);
  182.  
  183. /* If there is the possibility of multiple gDevices, then we */
  184. /* must check them to make sure we are zooming onto the right */
  185. /* display device when zooming out. */
  186. if ((code == inZoomOut) && gHasColorQD) {
  187.     /* window's portRect must be converted to global coordinates */
  188.     globalPortRect = whichWindow->portRect;
  189.     LocalToGlobal(&topLeft(globalPortRect));
  190.     LocalToGlobal(&botRight(globalPortRect));
  191.     /* must calculate height of window's title bar */
  192.     bias = globalPortRect.top - 1 - (*((WindowPeek)whichWindow)->strucRgn)->rgnBBox.top;
  193.     nthDevice = GetDeviceList();
  194.     greatestArea = 0;
  195.     /* This loop checks the window against all the gdRects in the */
  196.     /* gDevice list and remembers which gdRect contains the largest */
  197.     /* portion of the window being zoomed. */
  198.     while (nthDevice) {
  199.         (void)SectRect(&globalPortRect, &(*nthDevice)->gdRect, &theSect);
  200.         sectArea = (long)(theSect.right - theSect.left) * (theSect.bottom - theSect.top);
  201.         if (sectArea > greatestArea) {
  202.             greatestArea = sectArea;
  203.             dominantGDevice = nthDevice;
  204.             }
  205.         nthDevice = GetNextDevice(nthDevice);
  206.         }
  207.     /* We must create a zoom rectangle manually in this case. */
  208.     /* account for menu bar height as well, if on main device */
  209.     if (dominantGDevice == GetMainDevice())
  210.         bias += GetMBarHeight();
  211.     rectP = &(*dominantGDevice)->gdRect;
  212.     zoomRect.top = rectP->top + bias + 3;
  213.     zoomRect.left = rectP->left + 3;
  214.     zoomRect.bottom = rectP->bottom - 3;
  215.     zoomRect.right = rectP->right - 3;
  216.     /* Set up the WStateData record for this window. */
  217.     (*(WStateDataHandle)((WindowPeek)whichWindow)->dataHandle)->stdState = zoomRect;
  218.     }
  219. ZoomWindow(whichWindow, code, true);
  220.  
  221. }
  222.  
  223. /* DoCloseWindow: a window must be closed */
  224.  
  225. void DoCloseWindow(WindowPtr w, short whichMenuItem)
  226. {
  227. HideWindow(w);
  228. CheckItem(gMenu_Windows, whichMenuItem, false);
  229. }
  230.  
  231.  
  232. void DoUpdate(EventRecord *passEvt)
  233. {
  234. GrafPtr        savePort;
  235. register WindowPtr    w;
  236. register void (*theProc)(WindowPtr);
  237.  
  238. GetPort(&savePort);
  239. SetPort(w = (WindowPtr)passEvt->message);
  240. BeginUpdate(w);
  241. if (IsFabWindow(w)) {
  242.     theProc = (void (*)(WindowPtr)) ((FabWindowPtr)w)->updateProc;
  243.     if (theProc)
  244.         theProc(w);
  245.     }
  246. EndUpdate(w);
  247. SetPort(savePort);
  248. }
  249.  
  250. void DoActivate(EventRecord *passEvt)
  251. {
  252. register WindowPtr    whichWindow;
  253.  
  254. whichWindow = (WindowPtr)passEvt->message;
  255. DecideActivation(whichWindow, passEvt->where, passEvt->modifiers & 1);
  256. }
  257.  
  258. /* DecideActivation: common routine because of activate and
  259. suspend&resume events */
  260.  
  261. void DecideActivation(WindowPtr w, Point mouseGlob, Boolean active)
  262. {
  263. GrafPtr    savePort;
  264. register void (*theActivProc)(WindowPtr, Boolean);
  265.  
  266. GetPort(&savePort);
  267. SetPort(w);
  268.  
  269. if (IsFabWindow(w)) {
  270.     theActivProc = (void (*)(WindowPtr, Boolean)) ((FabWindowPtr)w)->activateProc;
  271.     if (theActivProc)
  272.         theActivProc(w, active);
  273.     }
  274. if (active) {
  275.     RecalcMouseRegion(w, mouseGlob);
  276.     }
  277. SetPort(savePort);
  278. }
  279.  
  280. void DoOSEvent(EventRecord *passEvt)
  281. {
  282. register WindowPtr    frontW = FrontWindow();
  283. register Boolean    willbeActive;
  284.  
  285. if ((*(Byte *)&passEvt->message) == suspendResumeMessage) {
  286.     InitCursor();
  287.     if (willbeActive = (CHARFROMMESSAGE(passEvt->message) & resumeFlag)) {
  288.         /* resume */
  289.         gInTheForeground = true;
  290.         if (CHARFROMMESSAGE(passEvt->message) & convertClipboardFlag)
  291.             (void)TEFromScrap();
  292.         }
  293.     else {
  294.         /* suspend */
  295.         gInTheForeground = false;
  296.         }
  297.     if (frontW)
  298.         DecideActivation(frontW, passEvt->where, willbeActive);
  299.     }
  300.  
  301. else if ((*(Byte *)&passEvt->message) == mouseMovedMessage) {
  302.         RecalcMouseRegion(frontW, passEvt->where);
  303.         }
  304. }
  305.  
  306. void main(void)
  307. {
  308. GrafPtr        savePort;
  309. Point        mousePos;
  310. WindowPtr    w;
  311. register void (*theProc)(WindowPtr);
  312. register void (*theDoGrowProc)(WindowPtr, EventRecord *);
  313. register RectPtr    wStateP;
  314. register long    sleep, maxLong = 0x7FFFFFFF;
  315. register short    code;
  316.  
  317. MaxApplZone();
  318. //UnloadSeg(_DATAINIT);
  319. InitAll();
  320. UnloadSeg(InitAll);
  321. do {
  322. if (gRstatus)
  323.     sleep = 0L;
  324. else if (gInTheForeground && gTheInput && ((*gTheInput)->selStart == (*gTheInput)->selEnd))
  325.     sleep = LMGetCaretTime();
  326. else
  327.     sleep = maxLong;
  328.  
  329.     if (WaitNextEvent(everyEvent, &gMyEvent, sleep, mouseRgn)) {
  330.         switch (gMyEvent.what) {
  331.             case nullEvent :
  332.                 DoIdle();
  333.             case mouseDown :
  334.                 code = FindWindow(gMyEvent.where, &w);
  335.                 switch (code) {
  336.                     case inMenuBar :
  337.                         AdjustMenus();
  338.                         Handle_My_Menu(MenuSelect(gMyEvent.where));
  339.                         break;
  340.                     case inDrag :
  341.                         DragWindow(w, gMyEvent.where, &qd.screenBits.bounds);
  342.                         GetPort(&savePort);
  343.                         SetPort(w);
  344.                         if (((WindowPeek)w)->spareFlag) {
  345.                             wStateP = &(*(WStateDataHandle)((WindowPeek)w)->dataHandle)->userState;
  346.                             *wStateP = w->portRect;
  347.                             LocalToGlobal(&topLeft(*wStateP));
  348.                             LocalToGlobal(&botRight(*wStateP));
  349.                             }
  350.                         if (IsFabWindow(w)) {
  351.                             theProc = (void (*)(WindowPtr)) ((FabWindowPtr)w)->dragProc;
  352.                             if (theProc)
  353.                                 theProc(w);
  354.                             RecalcGlobalCoords((FabWindowPtr)w);
  355.                             }
  356.                         GetMouse(&mousePos);
  357.                         LocalToGlobal(&mousePos);
  358.                         RecalcMouseRegion(w, mousePos);
  359.                         SetPort(savePort);
  360.                         break;
  361.                     case inGrow :
  362.                         GetPort(&savePort);
  363.                         SetPort(w);
  364.                         if (IsFabWindow(w)) {
  365.                             theDoGrowProc = (void (*)(WindowPtr, EventRecord *)) ((FabWindowPtr)w)->growProc;
  366.                             if (theDoGrowProc)
  367.                                 theDoGrowProc(w, &gMyEvent);
  368.                             ResizeObjects((FabWindowPtr)w);
  369.                             RecalcGlobalCoords((FabWindowPtr)w);
  370.                             }
  371.                         GetMouse(&mousePos);
  372.                         LocalToGlobal(&mousePos);
  373.                         RecalcMouseRegion(w, mousePos);
  374.                         SetPort(savePort);
  375.                         break;
  376.                     case inZoomIn :
  377.                     case inZoomOut :
  378.                         GetPort(&savePort);
  379.                         SetPort(w);
  380.                         if (TrackBox(w, gMyEvent.where, code)) {
  381.                             MyZoom(w, code);
  382.                             
  383.                             if (IsFabWindow(w)) {
  384.                                 theProc = (void (*)(WindowPtr)) ((FabWindowPtr)w)->zoomProc;
  385.                                 if (theProc)
  386.                                     theProc(w);
  387.                                 ResizeObjects((FabWindowPtr)w);
  388.                                 RecalcGlobalCoords((FabWindowPtr)w);
  389.                                 }
  390.                             }
  391.                         GetMouse(&mousePos);
  392.                         LocalToGlobal(&mousePos);
  393.                         RecalcMouseRegion(w, mousePos);
  394.                         SetPort(savePort);
  395.                         break;
  396.                     case inGoAway :
  397.                         if (TrackGoAway(w, gMyEvent.where)) {
  398.                             theProc = (void (*)(WindowPtr)) ((FabWindowPtr)w)->goAwayProc;
  399.                             if (theProc)
  400.                                 theProc(w);
  401.                             }
  402.                         break;
  403.                     case inContent :
  404.                         if (w != FrontWindow()) 
  405.                             SelectWindow(w);
  406.                         else {
  407.                             if (IsFabWindow(w)) {
  408.                                 GetPort(&savePort);
  409.                                 SetPort(w);
  410.                                 theDoGrowProc = (void (*)(WindowPtr, EventRecord *)) ((FabWindowPtr)w)->contentProc;
  411.                                 if (theDoGrowProc)
  412.                                     theDoGrowProc(w, &gMyEvent);
  413.                                 SetPort(savePort);
  414.                                 }
  415.                             }
  416.                         break;
  417.                     case inSysWindow :
  418.                         SystemClick(&gMyEvent, w);
  419.                         break;
  420.                     }
  421.                 break;
  422.             case keyDown:
  423.             case autoKey:
  424.                 DomyKeyEvent(&gMyEvent);
  425.                 break;
  426.             case updateEvt :
  427.                 DoUpdate(&gMyEvent);
  428.                 break;
  429.             case diskEvt :
  430.                 DoDiskEvent();
  431.                 break;
  432.             case activateEvt :
  433.                 DoActivate(&gMyEvent);
  434.                 break;
  435.             case app3Evt:
  436.                 if (--gNumAsyncSnds == 0)
  437.                     HUnlock((Handle)((SndChannelPtr)gMyEvent.message)->userInfo);
  438.                 (void)SndDisposeChannel((SndChannelPtr)gMyEvent.message, false);
  439.                 break;
  440.             case osEvt :
  441.                 DoOSEvent(&gMyEvent);
  442.                 break;
  443.             case kHighLevelEvent: {
  444.                 register OSErr    err;
  445.  
  446.                 if ((err = AEProcessAppleEvent(&gMyEvent)) != noErr)
  447.                     if (err != userCanceledErr) {
  448.                         AEErrorAlert(err);
  449.                         UnloadSeg(AEErrorAlert);
  450.                         }
  451.                 }
  452.             }
  453.         }
  454.     else
  455.         DoIdle();
  456.     }
  457. while (gDoneFlag == false);
  458. SavePreferencesFile();
  459. }
  460.  
  461. /* DoIdle: so that we have something to do while the user has nothing to do */
  462.  
  463. void DoIdle(void)
  464. {
  465. enum {
  466. kMIN_COMPUTE = 5L
  467. };
  468.  
  469. long    tickc;
  470. Boolean    stackProblems;
  471.  
  472. if (gInTheForeground)
  473.     if (gTheInput)
  474.         TEIdle(gTheInput);
  475.  
  476. if (gRstatus) {
  477.     if (CheckTheStack() == false) {
  478.         if (gPwrManagerIsPresent)
  479.             (void)IdleUpdate();
  480.         switch (gRstatus) {
  481.             case kST_GOING:
  482.                 tickc = TickCount();
  483.                 do {
  484.                     ExecuteInstructionsGO();
  485.                     stackProblems = CheckTheStack();
  486.                     }
  487.                 while ((TickCount() - tickc < kMIN_COMPUTE) && (stackProblems == false));
  488.                 break;
  489.             case kST_STEPASM:
  490.                 ExecuteInstructionsGO();
  491.                 StopIt();
  492.                 break;
  493.             case kST_STEPMPROG:
  494.                 ExecuteInstructions(gSubclk++);
  495.                 gSubclk &= 3;
  496.                 if (gSubclk == 0)
  497.                     gRstatus = kST_STOPPED;
  498.                 break;
  499.             case kST_STEPSUBCYC:
  500.                 ExecuteInstructions(gSubclk++);
  501.                 gSubclk &= 3;
  502.                 gRstatus = kST_STOPPED;
  503.                 break;
  504.             }
  505.         }
  506.     }
  507. }
  508.  
  509. Boolean CheckTheStack(void)
  510. {
  511. Boolean    result = true;
  512.  
  513. if ((unsigned short)gRegs[kREG_SP] > gPrefs.DefSPValue) {
  514.     if (gRegs[kREG_PC] == kPCExitToShell)
  515.         (void)NoteAlert_AE(kALRT_TOSHELL, myStdFilterProcNoCancel, myIdleFunct);
  516.     else
  517.         (void)StopAlert_AE(kALRT_STKUNDERFLOW, myStdFilterProcNoCancel, myIdleFunct);
  518.     StopIt();
  519.     }
  520. else if ((unsigned short)gRegs[kREG_SP] < (gPrefs.DefSPValue - gPrefs.DefStkSize)) {
  521.     (void)StopAlert_AE(kALRT_STKOVERFLOW, myStdFilterProcNoCancel, myIdleFunct);
  522.     StopIt();
  523.     }
  524. else
  525.     result = false;
  526. return result;
  527. }
  528.  
  529. /* AdjustMenus: we set the menus before MenuSelect or MenuKey.
  530. (Agh! This commonly used technique prevents tear-off menus) */
  531.  
  532. static void AdjustMenus(void)
  533. {
  534. register WindowPtr    window;
  535. long    offset;
  536. Boolean    undo = false;
  537. Boolean    cutCopyClear = false;
  538. Boolean    paste = false;
  539. Boolean    insertdelete = false;
  540. Boolean    go = false;
  541. Boolean    step = false;
  542. Boolean    stop = false;
  543.  
  544. if (window = FrontWindow()) {
  545.     if ( ISDAWINDOW(window) ) {
  546.         undo = true;                /* all editing is enabled for DA windows */
  547.         cutCopyClear = true;
  548.         paste = true;
  549.         }
  550.     else if ( ISAPPWINDOW(window) ) {
  551.     /* Cut, Copy, and Clear is enabled for appl. windows with selections */
  552.         if (gTheInput) {
  553.             EnableItem(gMenu_Edit, kMItem_Select_All);
  554.             if ( (*gTheInput)->selStart < (*gTheInput)->selEnd )
  555.                 cutCopyClear = true;
  556.             }
  557.         else
  558.             DisableItem(gMenu_Edit, kMItem_Select_All);
  559.         if ((window == gWPtr_Microprogram_Ed) && (keyDownDest == kKEY_LIST)) {
  560.             cutCopyClear = true;
  561.             if (theSelection[kL_COMMENTS] != maxLLine[kL_COMMENTS])
  562.                 insertdelete = true;
  563.             }
  564.     /* if there’s any text in the clipboard, paste is enabled */
  565.         if ((GetScrap(nil, 'TEXT', &offset)  > 0) &&
  566.             ((gTheInput) || ((window == gWPtr_Microprogram_Ed) && (keyDownDest == kKEY_LIST))))
  567.             paste = true;
  568.         }
  569.     if ( undo )
  570.         EnableItem(gMenu_Edit, kMItem_Undo);
  571.     else
  572.         DisableItem(gMenu_Edit, kMItem_Undo);
  573.     if ( cutCopyClear ) {
  574.         EnableItem(gMenu_Edit, kMItem_Cut);
  575.         EnableItem(gMenu_Edit, kMItem_Copy);
  576.         EnableItem(gMenu_Edit, kMItem_Clear);
  577.         }
  578.     else {
  579.         DisableItem(gMenu_Edit, kMItem_Cut);
  580.         DisableItem(gMenu_Edit, kMItem_Copy);
  581.         DisableItem(gMenu_Edit, kMItem_Clear);
  582.         }
  583.     if ( paste )
  584.         EnableItem(gMenu_Edit, kMItem_Paste);
  585.     else
  586.         DisableItem(gMenu_Edit, kMItem_Paste);
  587.     if ( insertdelete ) {
  588.         EnableItem(gMenu_Edit, kMItem_Insert);
  589.         EnableItem(gMenu_Edit, kMItem_Delete);
  590.         }
  591.     else {
  592.         DisableItem(gMenu_Edit, kMItem_Insert);
  593.         DisableItem(gMenu_Edit, kMItem_Delete);
  594.         }
  595.     }
  596. else {    /* no windows are open */
  597.     DisableItem(gMenu_Edit, kMItem_Undo);    /* check this when implementing undo */
  598.     DisableItem(gMenu_Edit, kMItem_Cut);
  599.     DisableItem(gMenu_Edit, kMItem_Copy);
  600.     DisableItem(gMenu_Edit, kMItem_Clear);
  601.     DisableItem(gMenu_Edit, kMItem_Paste);
  602.     DisableItem(gMenu_Edit, kMItem_Select_All);
  603.     DisableItem(gMenu_Edit, kMItem_Insert);
  604.     DisableItem(gMenu_Edit, kMItem_Delete);
  605.     }
  606.  
  607. if (((WindowPeek)gWPtr_Disasm)->visible)
  608.     EnableItem(gMenu_Control, kMItem_Disasmfrom);
  609. else
  610.     DisableItem(gMenu_Control, kMItem_Disasmfrom);
  611.  
  612. if (((WindowPeek)gWPtr_Dump)->visible)
  613.     EnableItem(gMenu_Control, kMItem_Dumpfrom);
  614. else
  615.     DisableItem(gMenu_Control, kMItem_Dumpfrom);
  616.  
  617. if (DocIsOpen) {
  618.     if (gRstatus == kST_STOPPED) {
  619.         go = true;
  620.         step = true;
  621.         }
  622.     if (gRstatus == kST_GOING) {
  623.         stop = true;
  624.         }
  625.     EnableItem(gMenu_Windows, kMItem_Microprogram);
  626.     EnableItem(gMenu_File, kMItem_Close);
  627.     EnableItem(gMenu_File, kMItem_Save_Control_St2);
  628.     EnableItem(gMenu_Control, kMItem_SelectCurMPC);
  629.     }
  630. else {
  631.     DisableItem(gMenu_Windows, kMItem_Microprogram);
  632.     DisableItem(gMenu_File, kMItem_Close);
  633.     DisableItem(gMenu_File, kMItem_Save_Control_St2);
  634.     DisableItem(gMenu_Control, kMItem_SelectCurMPC);
  635.     }
  636. if (go)
  637.     EnableItem(gMenu_Control, kMItem_Go);
  638. else
  639.     DisableItem(gMenu_Control, kMItem_Go);
  640. if (step) {
  641.     EnableItem(gMenu_Control, kMItem_StepSub);
  642.     EnableItem(gMenu_Control, kMItem_StepMicro);
  643.     EnableItem(gMenu_Control, kMItem_StepInstr);
  644.     }
  645. else {
  646.     DisableItem(gMenu_Control, kMItem_StepSub);
  647.     DisableItem(gMenu_Control, kMItem_StepMicro);
  648.     DisableItem(gMenu_Control, kMItem_StepInstr);
  649.     }
  650. if (stop)
  651.     EnableItem(gMenu_Control, kMItem_Stop);
  652. else
  653.     DisableItem(gMenu_Control, kMItem_Stop);
  654. if (gRstatus == kST_GOING) {
  655.     DisableItem(gMenu_Control, kMItem_ResetMem);
  656.     DisableItem(gMenu_Control, kMItem_ResetRegs);
  657.     }
  658. else {
  659.     EnableItem(gMenu_Control, kMItem_ResetMem);
  660.     EnableItem(gMenu_Control, kMItem_ResetRegs);
  661.     }
  662. } /*AdjustMenus*/
  663.  
  664. #pragma segment Rare
  665.  
  666. /* AEErrorAlert: errors while handling AEvents */
  667.  
  668. static void AEErrorAlert(OSErr reason)
  669. {
  670. enum {
  671. kALRT_AEPROCERR = 133
  672. };
  673.  
  674. Str255    tempS;
  675.  
  676. InitCursor();
  677. MyNumToString(reason, tempS);
  678. ParamText(tempS, nil, nil, nil);
  679. (void)StopAlert_UPP(kALRT_AEPROCERR, myStdFilterProcNoCancel);
  680. }
  681.  
  682. #pragma segment __%Main
  683.  
  684. #endif
  685.  
  686.